package com.gba.mark.user.auth.utils;

import com.gba.mark.user.auth.config.SelfUserDetails;
import org.springframework.security.core.Authentication;

public class AuthUtils {

    public static String getUsername(Authentication authentication){
        Object principal = authentication.getPrincipal();
        String user ;
        if(principal==null){
            return null;
        }
        try {
            user = (String) principal;
        }catch (Exception e){
            SelfUserDetails userDetails = (SelfUserDetails) principal;
            user = userDetails.getUsername();
        }
        return user;
    }

}
